<?php
$this->layout('head');
$tags =& $this->tags;
function getTagNameById($id, &$tags)
{
    return $tags[$id]['tag'];
}
//@curPage      1~$totalPage
//@totalPage    1+
function pageBar($params)
{
    if ($params['totalPage'] <= 1)
        return;
    $curPage = $params['curPage'];
    $totalPage = $params['totalPage'];
    unset($params['curPage'], $params['totalPage']);
    echo '<div class="blog" style="background-color:white;!important">';
    $params['page'] = 1;
    if ($curPage > 1){
        echo sprintf(_('%s首页%s'), '<a href="/index/index'.buildQuery($params) . '">', '</a>');
        $params['page'] = $curPage - 1;
        echo sprintf(_('%s上一页%s'), '<a href="/index/index'.buildQuery($params) . '">', '</a>');
    }
    if ($totalPage > $curPage){
        $params['page'] = $curPage + 1;
        echo sprintf(_('%s下一页%s'), '<a href="/index/index'.buildQuery($params) . '">', '</a>');
        $params['page'] = $totalPage;
        echo sprintf(_('%s末页%s'), '<a href="/index/index'.buildQuery($params) . '">', '</a>');
    }
    echo "<span class='pageInfo'>{$curPage}/{$totalPage}</span></div>";
}
?>
<script type="text/javascript">
Element.observe(window, 'load', function(){
    Event.observe('blogs', 'mouseover', function(event){
        var div = $(Event.findElement(event, 'DIV'));
        if (!div || !div.hasClassName('blog'))
            return;
        //阻止当div下的元素mouseout时对div产生的mouseover事件
        var relatedTarget = Prototype.Browser.IE ? event.toElement : event.relatedTarget;
        if (div != relatedTarget && div.descendants().include(relatedTarget) || div == relatedTarget)
            return;
        hideTagSuggest();
        div.addClassName('lineHover');
        var op = div.down('span.op');
        if (op){
            op.setStyle({visibility:'visible'});
            return;
        }
        var info = div.down('span.info');
        info.update(info.innerHTML + $('operation').innerHTML);
    });
    Event.observe('blogs', 'mouseout', function(event){
        var div = $(Event.findElement(event, 'DIV'));
        if (!div || !div.hasClassName('blog'))
            return;
        //阻止当鼠标移至div下元素时对div产生mouseout事件
        var relatedTarget = Prototype.Browser.IE ? event.toElement : event.relatedTarget;
        if (div != relatedTarget && div.descendants().include(relatedTarget) || div == relatedTarget)
            return;
        div.removeClassName('lineHover');
        var op = div.down('span.op');
        if (op)
            op.setStyle({visibility:'hidden'});
    });
    Event.observe('suggestTags', 'click', function(event){
        var a = $(Event.findElement(event, 'A'));
        if (!a || !a.hasClassName('tag'))
            return;
        insertTag(a);
    });
    Element.observe('blogTag', 'focus', showTagSuggest);
    Element.observe('blogTag', 'click', showTagSuggest);
    Element.observe('blogContent', 'focus', hideTagSuggest);
    $('blogContent').focus();
});
</script>
        <div id="ajaxMsg" style="visibility:hidden;"><img src="/images/ajax-loader.gif" /><?=_('正在加载，请稍候...')?></div>
        <div id="tagline"><?=_('标签：')?>
        <?$i=0;foreach($this->topTags as $tag):$i++;?>
            <a class="tag" href="/tag/name/<?=urlencode($tag['tag'])?>"><?=$tag['tag']?></a>
        <?if($i>10)break;endforeach;?>
        </div>
        <div id="blogs">
        <?
        $i = 0;
        if (!empty($this->blogs)):
            foreach ($this->blogs as $b):
        ?>
            <div blogid="<?=$b['id']?>" class="blog <?=($i%2?'odd':'even')?>"><span class="other"><img src="/images/time.gif" /><span title="<?=date($ENV['time.style'], $b['dateline'])?>"><?=friendlyDate($b['dateline'])?></span>, <img src="/images/tag.gif" /><?foreach($b['tags'] as $t):?><a class="tag" href="/tag/name/<?=urlencode(getTagNameById($t,$tags))?>" tabIndex="-1"><?=getTagNameById($t,$tags)?></a><?endforeach;?>    </span><span class="info"><?=($b['marked']?'<del>'.$b['content'].'</del>':$b['content'])?></span></div>
        <?
                $i++;
            endforeach;
            pageBar($this->params);
        else: ?>
            <div class="blog even"><?=_('暂无内容')?></div>
        <?endif;?>
        </div>
        <div id="submitForm">
            <form action="/blog/add" method="post">
                <label><?=_('内容：')?><input name="blogContent" id="blogContent" type="text" class="text" autocomplete="off" /></label>
                <label><?=_('标签：')?><input name="blogTag" id="blogTag" type="text" class="text" autocomplete="off" /></label>
                <label><input name="submit" id="submit" type="submit" value="<?=_('发送')?>" /></label>
        </div>
        <div id="operation" style="display:none;"><span class="op"><a href="#" title="<?=_('删除')?>" onclick="deleteBlog(this);return false;"><img src="/images/delete.gif" /></a><a href="#" title="<?=_('标记')?>" onclick="markBlog(this, true);return false;"><img src="/images/done.gif" /></a><a href="#" title="<?=_('取消标记')?>" onclick="markBlog(this, false);return false;"><img src="/images/undone.gif" /></a></span></div>
        <div id="suggestTags" style="display:none;"><?foreach($this->topTags as $t){?><a class="tag" href="#"><?=$t['tag']?></a>
            <?}?></div>
<?php $this->layout('foot');?>
